{extend name='layout/layout'}
{block name='content'}
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>添加接口</h5>
            </div>
            <div class="ibox-content">
                <form class="form-horizontal m-t" id="commentForm" method="post" action="{:url('add')}">
					<div class="form-group">
                        <label class="col-sm-3 control-label">选择分类：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="group_id" required="" aria-required="true">
                                <option value="">==请选择==</option>
                                {foreach $getGroup as  $k => $v}
										<option value="{$v.id}" selected="selected">{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
					
                    <div class="form-group">
                        <label class="col-sm-3 control-label">接口名称：</label>
                        <div class="input-group col-sm-4">
                            <input id="title" type="text" class="form-control" name="title" required=""
                                   aria-required="true">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">接口地址：</label>
                        <div class="input-group col-sm-4">
                            <input id="url" type="text" class="form-control" name="url" required=""
                                   aria-required="true">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">请求路径：</label>
                        <div class="input-group col-sm-4">
                            <input id="path" type="text" placeholder="版本号/控制器/方法" class="form-control" name="path" required=""
                                   aria-required="true">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">请求类型：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="method" required="" aria-required="true">
                                <option value="">请选择</option>
                                {foreach name="$methodList" item="v" key='k'}
                                <option value="{$k}" {if $v==
                                'post'}selected="selected"{/if}>{$v}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">验证签名：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="validate_sign" required="" aria-required="true">
                                <option value="1">是</option>
                                <option value="0" selected="selected">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">验证时间：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="validate_time" required="" aria-required="true">
                                <option value="1">是</option>
                                <option value="0" selected="selected">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">验证user_token：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="validate_u_token" required="" aria-required="true">
                                <option value="1" selected="selected">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">验证access_token：</label>
                        <div class="input-group col-sm-4">
                            <select class="form-control" name="validate_a_token" required="" aria-required="true">
                                <option value="1">是</option>
                                <option value="0" selected="selected">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">接口备注：</label>
                        <div class="input-group col-sm-4">
                            <input id="mark" type="text" class="form-control" name="mark">
                        </div>
                    </div>
                    <hr>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">请求参数</label>
                        <div class="input-group col-sm-8">
                            <table class="table requestList col-sm-push-10">
                                <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>描述</th>
                                    <th>长度</th>
                                    <th>类型</th>
                                    <th>过滤</th>
                                    <th>必须</th>
                                    <th>参数类型</th>
                                    <th>条件</th>
                                    <th>备注</th>
                                    <th>举例</th>
                                    <th>
                                        <i class="fa fa-plus btn requestAdd"></i>
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">响应参数</label>
                        <div class="input-group col-sm-8">
                            <table class="table responseList col-sm-push-10">
                                <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>描述</th>
                                    <th>长度</th>
                                    <th>类型</th>
                                    <th>过滤</th>
                                    <th>必须</th>
                                    <th>条件</th>
                                    <th>备注</th>
                                    <th>举例</th>
                                    <th>
                                        <i class="fa fa-plus btn responseAdd"></i>
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-6">
                            <button class="btn btn-primary" type="submit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
</div>
{/block}

{block name='js'}
<script type="text/javascript">

    function getTr(_id, type) {
        if (_id > 20) {
            layer.alert('参数不能超过20个');
            return false;
        }
        return '<tr> ' +
            '<td><input type="text" name="' + type + '[' + _id + '][name]" style="width: 80px;"></td> ' +
            '<td><input type="text" name="' + type + '[' + _id + '][title]" style="width: 80px;"></td> ' +
            '<td><input type="number" style="width: 40px;" value="0" name="' + type + '[' + _id + '][length]"></td> ' +
            '<td> <select class="form-control" name="' + type + '[' + _id + '][type]" aria-required="true">{foreach name="$fieldType" item="v" key="k"} <option value="{$k}">{$v}</option>{/foreach} </select> </td> ' +
            '<td> <select class="form-control" name="' + type + '[' + _id + '][filter]" aria-required="true"> <option value="">请选择</option>{foreach name="$encryptList" item="v"} <option value="{$v}">{$v}</option>{/foreach} </select> </td>' +
            '<td><select class="form-control" name="method" required="" aria-required="true">' +
            '{foreach name="$statusList" item="v" key="k"} ' +
            '<option value="{$k}" {if $k==1}selected="selected"{/if}>{$v}</option>' +
            '{/foreach} </select></td> ' +
            '<td><select class="form-control" name="' + type + '[' + _id + '][is_file]"><option>--请选择--</option>{foreach name="$paramType" item="v" key="k"} <option value="{$k}" {if $k==0}selected="selected"{/if}>{$v}</option>{/foreach} </select></td> ' +
            '<td><input type="text" name="' + type + '[' + _id + '][condition]"></td> ' +
            '<td><input type="text" name="' + type + '[' + _id + '][mark]"></td> ' +
            '<td><input type="text" name="' + type + '[' + _id + '][example]"></td> ' +
            '</tr>';
    }

    $(document).ready(function () {
        $('.requestAdd').click(function () {
            var _id = $('.requestList tbody tr').length + 1;
            $('.requestList tbody').append(getTr(_id, 'request'));
        });
        $('.responseAdd').click(function () {
            var _id = $('.responseList tbody tr').length + 1;
            $('.responseList tbody').append(getTr(_id, 'response'));
        });

    });
</script>
{/block}
